package Eyjafjalla.monster;

import Eyjafjalla.action.UpgradeAllBurnAction;
import Eyjafjalla.card.status.Burn_Eyjafjalla;
import Eyjafjalla.patch.PompeiiPatch;
import Eyjafjalla.power.WhiteCloudPower;
import Eyjafjalla.relic.ShadowOfPompeii;
import Eyjafjalla.relic.VolcanoMask;
import com.badlogic.gdx.math.MathUtils;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.animations.VFXAction;
import com.megacrit.cardcrawl.actions.common.*;
import com.megacrit.cardcrawl.actions.utility.WaitAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.MonsterStrings;
import com.megacrit.cardcrawl.powers.FlameBarrierPower;
import com.megacrit.cardcrawl.vfx.combat.FireballEffect;

public class Pompeii extends AbstractEyjafjallaMonster{
    public static final String ID = "eyjafjalla:Pompeii";
    private static final String MID_PATH = "pompeii/enemy_1050_lslime";
    private static final MonsterStrings monsterStrings;
    private static final EnemyType TYPE = EnemyType.ELITE;
    private static final String ATTACK_NAME = "Skill";
    private static final String IDLE_NAME = "Idle";
    private static final String DIE_NAME = "Die";

    static {
        monsterStrings = CardCrawlGame.languagePack.getMonsterStrings(ID);
    }

    int attack = 3;
    int attackTimes;
    int randomLower;
    int randomUpper;
    float waitTime = 0.3F;

    public Pompeii(float x,float y){
        super(monsterStrings.NAME,ID,TYPE,96,360F,300F,x,y);
        setSpine(MID_PATH,1F);
        setFastMode();
        this.state.setAnimation(0,IDLE_NAME,true);

        if(AbstractDungeon.ascensionLevel>=8){
            setHp(200+10*AbstractDungeon.floorNum);
        }
        else {
            setHp(200+8*AbstractDungeon.floorNum);
        }
        randomUpper = 7 + AbstractDungeon.actNum;
        if(AbstractDungeon.ascensionLevel>=18){
            randomLower = 5;
        }
        else {
            randomLower = 3;
        }
        this.damage.add(new DamageInfo(this,this.attack, DamageInfo.DamageType.NORMAL));

    }

    public void setFastMode(){
        state.setTimeScale(1);
        this.waitTime = 0.3F;
    }

    @Override
    public void usePreBattleAction() {
        if(AbstractDungeon.actNum>0)
            addToBot(new ApplyPowerAction(this,this,new FlameBarrierPower(this,AbstractDungeon.actNum),AbstractDungeon.actNum));
        super.usePreBattleAction();
    }

    @Override
    protected void getMove(int i) {
        if((i<70&&!lastTwoMoves((byte) 1))||lastMove((byte) 2)){
            //随机化
            attack = AbstractDungeon.monsterRng.random(randomLower,randomUpper);
            attackTimes = AbstractDungeon.monsterRng.random(randomLower,randomUpper);
            damage.get(0).base = attack;
            damage.get(0).output = attack;
            this.setMove((byte) 1,Intent.ATTACK,this.damage.get(0).base,attackTimes,true);
        }
        else {
            this.setMove((byte) 2,Intent.STRONG_DEBUFF);
        }
    }

    @Override
    public void takeTurn() {
        setFastMode();
        switch (this.nextMove){
            case 1:{
                randomUpper++;
                addToBot(new ChangeStateAction(this,"ATTACK"));
                for(int i =0;i<attackTimes;i++){
                    addToBot(new VFXAction(new FireballEffect(this.hb.cX + MathUtils.random(-40F*Settings.scale,40F*Settings.scale), this.hb.cY+ MathUtils.random(-40F*Settings.scale,40F*Settings.scale), AbstractDungeon.player.hb.cX+ MathUtils.random(-40F*Settings.scale,40F*Settings.scale), AbstractDungeon.player.hb.cY+ MathUtils.random(-40F*Settings.scale,40F*Settings.scale)), 0.1F));
                    addToBot(new DamageAction(AbstractDungeon.player,damage.get(0), AbstractGameAction.AttackEffect.FIRE));
                }
                break;
            }
            case 2:{
                addToBot(new UpgradeAllBurnAction(1));
                AbstractCard burn = new Burn_Eyjafjalla();
                burn.upgrade();
                addToBot(new MakeTempCardInDiscardAction(burn,5));
                break;
            }
        }

        addToBot(new RollMoveAction(this));
    }

    @Override
    public void changeState(String stateName) {
        switch (stateName){
            case "ATTACK":{
                this.state.setAnimation(0,ATTACK_NAME,false);
                this.state.addAnimation(0,IDLE_NAME,true,0F);
                break;
            }
            default:
                break;
        }
    }

    @Override
    public void damage(DamageInfo info) {
        super.damage(info);
        if(this.currentHealth<=0){
            AbstractDungeon.getCurrRoom().cannotLose = false;
        }
    }

    @Override
    public void die() {
        this.state.setTimeScale(1F);
        state.setAnimation(0,DIE_NAME,false);
        PompeiiPatch.rewardLevel = AbstractDungeon.floorNum;
        AbstractDungeon.player.relics.removeIf(r -> r.relicId == ShadowOfPompeii.ID || r.relicId == VolcanoMask.ID);
        AbstractDungeon.player.reorganizeRelics();
        this.deathTimer = 0.5F;
        super.die();
    }
}


